<template>
  <div class="app-container">
    <div>
      <div class="search">
        <div class="search_info">
          <div class="mr20">
            分院: {{ $route.query.branchName }}
          </div>
          <div class="mr20">
            专业: {{ $route.query.majorName }}
          </div>
          <div class="mr20">
            班级: {{ $route.query.className }}
          </div>
          <div>
            <el-select
              class="school_semester"
              v-model="params.schoolSemesterId"
              placeholder="请选择学期"
              @change="changeSchoolSemester"
            >
              <el-option
                v-for="item in schoolSemesterList"
                :key="item.semesterId"
                :label="item.semesterName"
                :value="item.semesterId"
              >
              </el-option>
            </el-select>
          </div>
        </div>
        <el-button @click="exportExcel" type="primary">
          导出EXCEL
        </el-button>
      </div>
    </div>
    <div class="table">
      <el-table
        height="calc(100vh - 500px)"
        v-loading="loading"
        :data="postList"
      >
        <el-table-column label="课程" align="center" prop="courseName"/>
        <el-table-column label="课程学习状态" align="center" prop="majorName">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.finishStatus == '1' ? 'success' : 'warning'"
            >
              {{ scope.row.finishStatus == '1' ? '已结束' : '未结束' }}
            </el-tag>
          </template>
        </el-table-column>
        .
        <el-table-column label="目前班级平均成绩" align="center" prop="avgScore"/>
        <el-table-column label="平均在线学习时长（小时）" align="center" prop="avgStudyTime"/>
        <el-table-column label="课程创建老师" align="center" prop="principalName"/>
        <el-table-column label="辅助教师" align="center" prop="teachers"/>
      </el-table>
    </div>
  </div>
</template>

<script>
import { getSchoolSemesterList, getClassGrades } from '@/api/schoolSemester/schoolSemester'

export default {
  name: 'classStudyScore',
  data() {
    return {
      loading: false,
      postList: [],
      params: {
        //学期id
        schoolSemesterId: this.$store.getters.schoolInfo.semesterId
      },
      //学期列表
      schoolSemesterList: []
    }
  },
  created() {
    this.getSchoolSemester()
    this.getClassGrades()
  },
  methods: {
    async exportExcel() {
      this.download(`/school/manager/grades/exportClassAllCourseGrades/${this.$route.query.classId}`, { schoolSemesterId: this.params.schoolSemesterId }, `${this.$route.query.className}.xlsx`)
    },
    async getClassGrades() {
      this.loading = true
      let res = await getClassGrades(this.params.schoolSemesterId, this.$route.query.classId)
      if (res.code == 200) {
        this.loading = false
        this.postList = res.data
      }
    },
    changeSchoolSemester() {
      this.getClassGrades()
    },
    async getSchoolSemester() {
      let res = await getSchoolSemesterList()
      const { code, rows } = res
      if (code == 200) {
        this.schoolSemesterList = rows
      }
    }
  }
}
</script>

<style scoped lang="scss">
.search {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  box-sizing: border-box;

  .search_info {
    display: flex;
    align-items: center;

    .school_semester {
      margin-left: 20px;
    }
  }
}
</style>
